package com.example.demo.com.java8;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPClient {
    public static void main(String[] args) throws Exception {
        //1.定义服务器的地址、端口号、数据
        InetAddress address = InetAddress.getByName("localhost");
        int port = 8099;
        String info = "3,19900000001,20171101155915,1,113.26171805987126,23.239234619127426,0.0,192,82|83,WS001,JYFW04211025511643499,13570577458;" +
                "3,19900000001,20171101155915,1,113.26171805987126,23.239234619127426,0.0,192,82|83,WS001,JYFW0421102551164198,13570577458;";
        byte[] data = info.getBytes();
        //2.创建数据报
        DatagramPacket packet = new DatagramPacket(data,data.length,address,port);
        //3.创建DatagramSocket
        DatagramSocket socket = new DatagramSocket();
        //向服务端发送数据报
        while (true){
            Thread.sleep(2000);
            socket.send(packet);
        }
    }
}
